﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.Permission.Interfaces;
using Microhard.WarehouseInsp.Buz.DataAccess;
using Microhard.WarehouseInsp.Buz.BuzEnum;

namespace Microhard.WarehouseInsp.Buz.Impls
{
    public class ChangePlgPriceScope : ICustomeDataPermissionValidator
    {
        public bool HasPermission(List<Guid> identity)
        {
            //如果不是数据专员登录，则直接返回
            if (!this.scope.CurrentUserRoleNames.Contains(SysConst.PMROLENAME))
                return false;
            WarehouseInspEntities db = new WarehouseInspEntities();
            //需要对项目有管辖权限
            var plg = db.PledgeChangeRecords.Where(p => p.PledgePlanInRecord.SupProject.PMID == this.scope.CurrentUserID).ToList();
            if (plg == null || plg.Count == 0)
                return false;
            foreach (var g in identity)
            {
                bool cnt = plg.Select(p => p.PledgeProductID).ToList().Contains(g);
                if (cnt == false)
                    return false;
            }
            return true;
        }

        public Core.DBUtility.ScopeResult scope
        {
            set;
            get;
        }
    }
}
